#ifndef __VMSGS_H__
#define __VMSGS_H__

#include "config.h"
#include "vim.h"
#define VGDB_VMA_LEN    256

#define VGDB_VMT_C      0
#define VGDB_VMT_F      1
#define VGDB_VMT_R      2
#define VGDB_VMT_E      3
#define VGDB_VMT_S      4

typedef struct{
    int     vmid;
    int     bid;
    int     seqno;
    char    args[VGDB_VMA_LEN];
}vmsg_t;


typedef void (*vmfunc)(vmsg_t *);
typedef struct{
    vmfunc  func;
    char   *name;
}vmf_t;
#define VGDB_VMF_TBL_LEN    256
extern vmf_t    g_vmf_tbl[VGDB_VMF_TBL_LEN];




extern void     vmsg_init();
extern int      vmsg_hash(const char *, int, int, int);


extern void     vmsg_proc ();
extern vmsg_t  *vmsg_parse(vmsg_t *, const char *);

extern void     vmsgr_reply         (vmsg_t *);
extern void     vmsge_ballooneval   (vmsg_t *);
extern void     vmsge_balloontext   (vmsg_t *);
extern void     vmsge_buttonrelease (vmsg_t *);
extern void     vmsge_disconnect    (vmsg_t *);
extern void     vmsge_fileclosed    (vmsg_t *);
extern void     vmsge_filemodified  (vmsg_t *);
extern void     vmsge_fileopened    (vmsg_t *);
extern void     vmsge_geometry      (vmsg_t *);
extern void     vmsge_insert        (vmsg_t *);
extern void     vmsge_invokeaction  (vmsg_t *);
extern void     vmsge_keycommand    (vmsg_t *);
extern void     vmsge_keyatpos      (vmsg_t *);
extern void     vmsge_killed        (vmsg_t *);
extern void     vmsge_newdotandmark (vmsg_t *);
extern void     vmsge_quit          (vmsg_t *);
extern void     vmsge_remove        (vmsg_t *);
extern void     vmsge_revert        (vmsg_t *);
extern void     vmsge_save          (vmsg_t *);
extern void     vmsge_startupdone   (vmsg_t *);
extern void     vmsge_unmodified    (vmsg_t *);
extern void     vmsge_version       (vmsg_t *);
extern void     vmsgs_accept        (vmsg_t *);
extern void     vmsgs_auth          (vmsg_t *);
extern void     vmsgs_disconnect    (vmsg_t *);
extern void     vmsgs_detach        (vmsg_t *);
extern void     vmsgs_reject        (vmsg_t *);

#define vmsg_func(vmid)         ((g_vmf_tbl+(vmid))->func)
#define send_vmsg(vmsg)         ((vmsg_func((vmsg)->vmid))(vmsg))
#define vmsg_exec(vmsg)         ((vmsg_func((vmsg)->vmid))(vmsg))
#define vmsg_vmid(vstr, id)     (vmsg_hash(vstr, 1, VGDB_VMF_TBL_LEN, id))
#define vmsg_send(...)          do{char _local_cmd[512];sprintf(_local_cmd,__VA_ARGS__);send(vim()->datsock,_local_cmd,strlen(_local_cmd),0);vim()->seqno++;}while(0)

#define DEBUG_MESSAGE(...) fprintf(stderr,__VA_ARGS__)


#endif
